﻿using System;
using System.Text;
using VCDIFF.Commands;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace VCDIFF.Tests.CommandsTest
{
    
    
    /// <summary>
    ///This is a test class for RunTest and is intended
    ///to contain all RunTest Unit Tests
    ///</summary>
    [TestClass()]
    public class RunTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for Size
        ///</summary>
        [TestMethod()]
        public void SizeTest()
        {
            UInt64 size = 2;
            byte runByte = 0x01;
            Run target = new Run(size, runByte);
            UInt64 expected = 2;
            UInt64 actual;
            target.Size = expected;
            actual = target.Size;
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for RunByte
        ///</summary>
        [TestMethod()]
        public void RunByteTest()
        {
            UInt64 size = 2;
            byte runByte = 0x01;
            Run target = new Run(size, runByte);
            byte expected = 0x01;
            byte actual;
            target.RunByte = expected;
            actual = target.RunByte;
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for Run Constructor
        ///</summary>
        [TestMethod()]
        public void RunConstructorTest()
        {
            UInt64 size = 0;
            byte runByte = 0;
            Run target = new Run(size, runByte);
        }

        /// <summary>
        ///A test for ToByteArray
        ///</summary>
        [TestMethod()]
        public void ToByteArrayTest()
        {
            UInt64 size = 2;
            byte runByte = 0x65;
            Run target = new Run(size, runByte);

            byte[] expected = new byte[3] { 0x02, (byte)size, runByte };
            byte[] actual = target.ToByteArray();
            bool same = true;

            if (expected.Length != actual.Length)
                same = false;
            else
                for (int i = 0; i < expected.Length; i++)
                    if (expected[i] != actual[i])
                        same = false;

            Assert.AreEqual(true, same);
        }

        /// <summary>
        ///A test for Execute
        ///</summary>
        [TestMethod()]
        public void ExecuteTest()
        {
            UInt64 size = 2;
            byte runByte = 0x65;
            Run run = new Run(size, runByte);

            byte[] target = new byte[4] { 0x67, 0x68, 0x69, 0x6A };
            byte[] expected = new byte[6] { 0x67, 0x68, 0x69, 0x6A, 0x65, 0x65 };
            byte[] actual = run.Execute(target);
            bool same = true;

            if (expected.Length != actual.Length)
                same = false;
            else
                for (int i = 0; i < expected.Length; i++)
                    if (expected[i] != actual[i])
                        same = false;

            Assert.AreEqual(true, same);
        }
    }
}
